package com.jues.huichain.login.model;

import com.google.gson.GsonBuilder;
import com.jues.huichain.login.entity.AppUpdataEntity;
import com.jues.huichain.login.entity.BootPageEntity;
import com.jues.huichain.login.entity.CodeEntity;
import com.jues.huichain.login.entity.EntranceEntity;
import com.jues.huichain.login.entity.EntranceResultEntity;
import com.jues.huichain.login.entity.GlobalConfigEntity;
import com.jues.huichain.login.entity.RegisterBusinessListEntity;
import com.jues.huichain.login.entity.RegisterDepartmentListEntity;
import com.jues.huichain.login.entity.RegisterPositionListEntity;
import com.jues.huichain.login.entity.RegisterRequest;

import org.json.JSONObject;

import health.lm.com.data.App;
import health.lm.com.data.HttpCST;
import health.lm.com.network.EasyHttp;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.network.utils.MyApi;

/**
 * Created by Android Studio .
 * 作者：zhong
 * 日期：2018/12/2
 * 邮箱：15206394364@163.com
 * 介绍：注册登录忘记密码等
 * 修订：====================
 */
public class EntranceModel {
    private static EntranceModel entranceModel;

    public static EntranceModel getInstance() {
        if (null == entranceModel) entranceModel = new EntranceModel();
        return entranceModel;
    }

    /**
     * 注册接口
     */
    public void register(RegisterRequest entranceEntity, SimpleCallBack<EntranceResultEntity.ResultDataBean> pCallBack) {
        try {
            JSONObject jsonObject = new JSONObject(new GsonBuilder().create().toJson(entranceEntity));
            String json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1001, jsonObject);
            EasyHttp.post("/").upJson(json).execute(pCallBack);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void login(EntranceEntity entranceEntity, SimpleCallBack<EntranceResultEntity.ResultDataBean> pCallBack) {
        try {
            JSONObject jsonObject = new JSONObject(new GsonBuilder().create().toJson(entranceEntity));
            String json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1002, jsonObject);
            //HttpApi.getInstance(EntranceResultEntity.class).jsonApi(json, callback);
            EasyHttp.post("/").upJson(json).execute(pCallBack);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void forgot(EntranceEntity entranceEntity, SimpleCallBack<Object> pCallBack) {
        try {
            JSONObject jsonObject = new JSONObject(new GsonBuilder().create().toJson(entranceEntity));
            String json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1004, jsonObject);
            EasyHttp.post("/").upJson(json).execute(pCallBack);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void getCode(CodeEntity codeEntity, SimpleCallBack<Object> pCallBack) {
        try {
            JSONObject jsonObject = new JSONObject(new GsonBuilder().create().toJson(codeEntity));
            String json = MyApi.getInstance().generateMessage(HttpCST.MODULE_UTILS, HttpCST.INTFC_1001, jsonObject);
            EasyHttp.post("/").upJson(json).execute(pCallBack);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 启动图接口
     *
     * @param pCallBack pCallBack
     */
    public void getBootPage(SimpleCallBack<BootPageEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, "");
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_UTILS, HttpCST.INTFC_1001, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 全局配置接口
     *
     * @param pCallBack pCallBack
     */
    public void getGlobalConfigData(SimpleCallBack<GlobalConfigEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, "");
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_UTILS, HttpCST.INTFC_1002, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * App版本更新检查
     *
     * @param version   版本号
     * @param pCallBack pCallBack
     */
    public void appUpdate(String version, SimpleCallBack<AppUpdataEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            jsonObject.put("version", version);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_UTILS, HttpCST.INTFC_1005, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 极光推送，注册码
     *
     * @param jpush_code 注册成功后的码
     * @param pCallBack  pCallBack
     */
    public void appPush(String jpush_code, SimpleCallBack<Object> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            jsonObject.put("jpush_code", jpush_code);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1036, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 获取注册职务列表
     *
     * @param pCallBack 回调
     */
    public void getPositionList(SimpleCallBack<RegisterPositionListEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1030, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 获取注册部门列表
     *
     * @param pCallBack 回调
     */
    public void getDepartmentList(SimpleCallBack<RegisterDepartmentListEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1031, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 获取注册 行业列表
     *
     * @param parent_mobile 推荐人手机号
     * @param pCallBack     回调
     */
    public void getBusinessList(String parent_mobile, SimpleCallBack<RegisterBusinessListEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            jsonObject.put("parent_mobile", parent_mobile);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1032, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }
}
